<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="admin::header"></head>
<section>
    <script>
        var ids = "";
        //fixModel
        fixModel = function (type) {
            //$("#modal-fix").modal();
            // $("#modal-2").modal("hide");
            // $("#profile1").addClass("active");
            $.ajax({
                type: "POST",
                data: {type: type},
                url: "/exam/model/getALLModel",
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        window.location.href = ("/exam/model/addExam");
                    } else {
                        var str = "";
                        $.each(data,function (index,value) {
                            str += '<tr>';
                            str += '<td>' + (index +1 ) + '</td>';
                            str += '<td>' + value.model.title + '</td>';
                            str += '<td>' + value.type + '</td>';
                            str += '<td>' + value.difficulty + '</td>';
                            str += '<td>' + value.model.author + '</td>';
                            str += '<td>' + value.model.grade + '</td>';
                            str += '<td><div class=\"checkbox\"><label><input type=\'checkbox\' name=\'add\' value='+value.model.modelId+' />添加</label></div></td>';
                            str += '</tr>';
                            // alert(str);
                            // alert(value.model.answer);
                        });
                        $("#tbody").html(str);
                        // $("#modal-2").modal();
                        // $(this).tab('show');
                        // $('#profile1').find('tbody').html(str);
                        // $("#profile1").show();
                        // $(this).tab('show');//显示当前选中的链接及关联的content
                    }
                }
            });
        }
        fixConfirm = function () {
            $.ajax({
                type: "POST",
                url: "/exam/model/update",
                data: {
                    modelId: $("#modelId").val(),
                    title: $("#title").val(),
                    answer: $("#answer").val(),
                    difficulty: $("#difficulty").val(),
                },
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        alert("修改失败！请联系管理员...");
                    } else {
                        $.each(data, function (key, value) {
                            alert(value);
                        })
                    }
                    $("#modal-update").modal('hide');
                    window.location.href = ("/exam/model/select?type=");
                }
            });
        }
        addModel = function (type) {
            $.ajax({
                type: "POST",
                data: {type: type},
                url: "/exam/model/getALLModel",
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        window.location.href = ("/exam/model/addExam");
                    } else {
                        var str = "";
                        $.each(data,function (index,value) {
                            str += '<tr>';
                            str += '<td>' + (index+1) +'</td>';
                            str += '<td>' + value.model.title + '</td>';
                            str += '<td>' + value.type + '</td>';
                            str += '<td>' + value.difficulty + '</td>';
                            str += '<td>' + value.model.author + '</td>';
                            str += '<td>' + value.model.grade + '</td>';
                            str += '<td><div class=\"checkbox\"><label><input type=\'checkbox\' name=\'add\' value='+value.model.modelId+' onclick=\'checkClick()\' />添加</label></div></td>';
                            str += '</tr>';
                            // alert(str);
                            // alert(value.model.answer);
                        });
                        $("#tbody").html(str);
                        $("#modal-2").modal();
                    }
                }
            });
        }
        checkClick = function () {

            $('input[name="add"]:checked').each(function(i){
                if(0==i){
                    ids = $(this).val();
                }else{
                    ids += (","+$(this).val());
                }
            });
            // alert(headers);
        }


        saveExam = function () {
            $("#ids").val(ids);
            // $("#exam_type").val(0);//默认组卷类型
            $("#modal-2").modal('hide');

        }
        addExam = function(){
            if ($("#exam_name").val() == ""){
                alert("试卷名称不能为空！");
                return;
            }
            if ($("#need_time").val() == ""){
                alert("考试时间不能为空！");
                return;
            }
            if ($("#exam_author").val() == ""){
                alert("发布者不能为空！");
                return;
            }
            $.ajax({
                type:"POST",
                data:{
                    exam_name:$("#exam_name").val(),
                    need_time:$("#need_time").val(),
                    exam_author:$("#exam_author").val()
                },
                url:"/exam/exam/add",
                dataType:"json",
                success:function (data) {
                    if (data == null){
                        alert("添加失败，请联系管理员...");
                    }else{
                        $.each(data,function (key,value) {
                            alert(value);

                        });
                        window.location.href = ("/exam/page/addExam");
                    }
                }
            });
        }


    </script>
</section>
<body class="sidebar-fixed header-fixed">
<div class="page-wrapper">
    <!--导入上边栏-->
    <nav class="navbar page-header" th:include="admin::admin-navbar"></nav>
    <div class="main-container">
        <!--导入侧边栏-->
        <div class="sidebar" th:include="admin::admin-sidebar"></div>
        <div class="content">
            <div class="container-fluid">
                <h1 style="text-align: center;font-size: 30px">新增试卷</h1>
                <form th:action="@{/exam/add}" method="post">
                    <div class="row">
                        <div class="col-md-4" style="font-size: 20px">

                            <div class="form-group">
                                <label class="form-control-label">组卷类型</label>
                            </div>
                            <div class="form-group">
                                <div class="col-md-6 mb-4 open">
                                    <ul class="nav nav-tabs" role="tablist" style="font-size: 15px">
                                        <li class="nav-item">
                                            <a class="nav-link active" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="false">固定试题&nbsp;&nbsp;<label style="font-size: 10px;color: gray">考生试题相同</label></a>
                                        </li>

                                        <li class="nav-item">
                                            <a class="nav-link" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="true">随机试题&nbsp;&nbsp;<label style="font-size: 10px;color: gray">考生试题不同</label></a>
                                        </li>
                                    </ul>
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="home" role="tabpanel">
                                            <!--<a id="add-btn" class="btn btn-outline-primary"-->
                                            <!--th:onclick="'javascript:addModel('+0+');'">添加试题-->
                                            <!--</a>-->
                                            <div class="control-label">
                                                <a class="btn btn-outline-primary" th:href="@{/exam/getALLModel(title=null,type=null)}">手动添加试题</a>
                                            </div>
                                            <br />
                                            <div class="control-label">
                                                <a class="btn btn-outline-primary" th:href="@{/exam/getALLModel(title=null,type=null)}">自动添加试题</a>
                                            </div>
                                            <!--<button class="btn btn-outline-primary" data-toggle="modal" data-target="#modal-2">添加试题</button>-->
                                        </div>

                                        <div class="tab-pane" id="profile" role="tabpanel">
                                            <div class="control-label">
                                                <a class="btn btn-outline-primary">系统随机试题</a>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exam_name" class="form-control-label">试卷名称</label>
                                <input name="exam_name" id="exam_name" class="form-control" value=""
                                       placeholder="请输入试卷名称" required>
                                <input name="ids" type="hidden" id="ids" />
                                <!--默认组卷类型-->
                                <!--<input name="exam_type" type="hidden" id="exam_type" />-->
                            </div>
                            <div class="form-group">
                                <label for="need_time">所需时间</label>
                                <select name="need_time" id="need_time" class="form-control" required>
                                    <option value="30">30分钟</option>
                                    <option value="60">60分钟</option>
                                    <option value="90">90分钟</option>
                                    <option value="120">120分钟</option>
                                    <option value="150">150分钟</option>
                                    <option value="180">180分钟</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="exam_author" class="form-control-label">发布者</label>
                                <input name="exam_author" id="exam_author" class="form-control" value=""
                                       placeholder="请输入发布者" required>
                            </div>
                            <div class="form-group" style="margin-top: 35px">
                                <div class="mb-4">
                                    <button class="btn btn-primary" type="button" th:onclick="'javascript:addExam()'">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>
</div>
<div class="modal fade" id="modal-fix" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header bg-primary border-0">
                <h5 class="modal-title text-white">试题选择</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <!--输入框-->
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <div class="card p-3">
                            <div class="card-body d-flex justify-content-between align-items-center">
                                <div>
                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+1+');'" href="javascript:void(0)">选词填空</a></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card p-3">
                            <div class="card-body d-flex justify-content-between align-items-center">
                                <div>
                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+2+');'" href="javascript:void(0)">段落匹配</a></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card p-3">
                            <div class="card-body d-flex justify-content-between align-items-center">
                                <div>
                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+3+');'" href="javascript:void(0)">仔细阅读</a></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card p-3">
                            <div class="card-body d-flex justify-content-between align-items-center">
                                <div>
                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+4+');'" href="javascript:void(0)">翻译</a></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card p-3">
                            <div class="card-body d-flex justify-content-between align-items-center">
                                <div>
                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+5+');'" href="javascript:void(0)">写作</a></span>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="card">
                            <div class="card-header bg-light">
                                题库列表
                            </div>

                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-hover">
                                        <thead>
                                        <tr>
                                            <th>序号</th>
                                            <th>标题</th>
                                            <th>类型</th>
                                            <th>难度</th>
                                            <th>作者</th>
                                            <th>分值</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="tbody1">
                                            <tr>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer border-0">
                <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" th:onclick="'javascript:fixConfirm()'">Continue
                </button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="modal-2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">试题选择</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <div class="col-md-6 mb-4">
                    <ul class="nav nav-tabs" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" data-toggle="tab" href="#home1" role="tab" aria-controls="home">从题库随机选择试题</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#profile1" role="tab" aria-controls="profile">手动从题库中选择试题</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="home1" role="tabpanel">
                            从题库随机选择试题<br />
                            从题库随机选择试题<br />
                            从题库随机选择试题<br />
                            从题库随机选择试题
                        </div>

                        <div class="tab-pane" id="profile1" role="tabpanel">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="card p-3">
                                            <div class="card-body d-flex justify-content-between align-items-center">
                                                <div>
                                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+0+');'" href="javascript:void(0)">全部试题</a></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card p-3">
                                            <div class="card-body d-flex justify-content-between align-items-center">
                                                <div>
                                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+1+');'" href="javascript:void(0)">选词填空</a></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card p-3">
                                            <div class="card-body d-flex justify-content-between align-items-center">
                                                <div>
                                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+2+');'" href="javascript:void(0)">段落匹配</a></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card p-3">
                                            <div class="card-body d-flex justify-content-between align-items-center">
                                                <div>
                                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+3+');'" href="javascript:void(0)">仔细阅读</a></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card p-3">
                                            <div class="card-body d-flex justify-content-between align-items-center">
                                                <div>
                                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+4+');'" href="javascript:void(0)">翻译</a></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="card p-3">
                                            <div class="card-body d-flex justify-content-between align-items-center">
                                                <div>
                                                    <span class="font-weight-light"><a th:onclick="'javascript:fixModel('+5+');'" href="javascript:void(0)">写作</a></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="card">
                                            <div class="card-header bg-light">
                                                题库列表
                                            </div>

                                            <div class="card-body">
                                                <div class="table-responsive">
                                                    <table class="table table-hover">
                                                        <thead>
                                                        <tr>
                                                            <th>序号</th>
                                                            <th>标题</th>
                                                            <th>类型</th>
                                                            <th>难度</th>
                                                            <th>作者</th>
                                                            <th>分值</th>
                                                            <th>操作</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody id="tbody">
                                                        <tr>
                                                        </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" th:onclick="'javascript:saveExam();'">Save</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>